-- Options are automatically loaded before lazy.nvim startup
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
-- Add any additional options here

-- Autoformat
-- vim.g.autoformat = true

local opt = vim.opt

-- Setup treesitter code folding.
-- opt.foldmethod = "expr"
-- opt.foldexpr = "nvim_treesitter#foldexpr()"

-- Set the conceallevel.
-- opt.conceallevel = 0

-- Set wrap.
-- opt.wrap = true

-- Set formatoptions
-- opt.formatoptions = "jqlnt"

-- 文件操作：Backup&Undo
vim.cmd([[

  silent !mkdir -p ~/.config/nvim/tmp/backup
  silent !mkdir -p ~/.config/nvim/tmp/undo
  "silent !mkdir -p ~/.config/nvim/tmp/sessions
  set backupdir=~/.config/nvim/tmp/backup,.
  set directory=~/.config/nvim/tmp/backup,.
  if has('persistent_undo')
    set undofile
    set undodir=~/.config/nvim/tmp/undo,.
  endif


]])

-- au BufReadPost * if line("'"") > 0|if line("'"") <= line("$")|exe("norm '"")|else|exe "norm $"|endif|endif

-- vim.cmd([[

-- autocmd BufRead * autocmd BufWinEnter * ++once normal! zx

-- au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

-- ]])

-- Necessary Commands to Execute
-- vim.cmd('exec "nohlsearch"')

-- GitGutter 保存时更新git状态
vim.cmd("autocmd BufWritePost * GitGutter")

--中英文输入法切换
vim.cmd([[

let g:input_toggle = 1
function! Fcitx2en()
  let s:input_status = system("fcitx5-remote")
  if s:input_status == 2
    let g:input_toggle = 1
    let l:a = system("fcitx5-remote -c")
  endif
endfunction

function! Fcitx2zh()
  let s:input_status = system("fcitx5-remote")
  if s:input_status != 2 && g:input_toggle == 1
    let l:a = system("fcitx5-remote -o")
    let g:input_toggle = 0
  endif
endfunction

autocmd InsertLeave * call Fcitx2en()

]])

vim.cmd("let g:ranger_map_keys = 0")

--- Colorizer
vim.cmd("let g:colorizer_syntax = 1")

--- Nerd-Commenter
vim.cmd("let g:NERDSpaceDelims=1")

vim.cmd("let g:autoformat_verbosemode=1")
vim.cmd('let g:formatter_yapf_style = "pep8"')

-- 底部状态栏 eleline
-- vim.cmd('let g:eleline_powerline_fonts = 0')
-- Virtual-Multi
vim.cmd([[

"let g:VM_theme             = 'iceblue'
"let g:VM_default_mappings = 0
let g:VM_leader                     = {'default': ',', 'visual': ',', 'buffer': ','}
let g:VM_maps                       = {}
"let g:VM_custom_motions             = {'i': 'k', 'j': 'h', 'k': 'j', 'h': 'i'}
"let g:VM_maps['i']                  = 'h'
"let g:VM_maps['I']                  = 'H'
let g:VM_maps['Find Under']         = '<C-m>'
let g:VM_maps['Find Subword Under'] = '<C-m>'
let g:VM_maps['Find Next']          = 'n'
let g:VM_maps['Find Prev']          = 'N'
let g:VM_maps['Remove Region']      = 'q'
let g:VM_maps['Skip Region']        = '<c-x>'
let g:VM_maps["Undo"]               = '<C-z>'
let g:VM_maps["Redo"]               = '<C-y>'


]])

-- map('n','<CR>','<Plug>(VM-Visual-All)',{})
--浮动终端
vim.cmd([[
  let g:floaterm_opener = 'tabe'
  let g:floaterm_height = 0.8
  let g:floaterm_width = 0.8
]])

-- Markdown Settings
---
-- Snippets
-- source $XDG_CONFIG_HOME/nvim/md-snippets.vim
vim.cmd("source $HOME/.config/nvim/other/md-snippets.vim")
-- auto spell
vim.cmd("autocmd BufRead,BufNewFile *.md setlocal spell")

-- rainbow 彩虹括号
-- vim.cmd("let g:rainbow_active = 1")
--
-- 运行

-- vim.cmd([[

-- noremap <F5> :call CompileRunGcc()<CR>
-- func! CompileRunGcc()
-- exec "w"
-- if &filetype == 'c'
-- :FloatermNew --autoclose=0 --wintype=split --height=0.8 gcc % -o %< && ./%<
-- :res -15
-- elseif &filetype == 'cpp'
-- :FloatermNew --autoclose=0 --wintype=split --height=0.4 g++ -std=c++11 % -Wall -o %< && ./%<
-- ":term ./%<
-- " elseif &filetype == 'java'
-- " exec "!javac %"
-- " exec "!time java %<"
-- elseif &filetype == 'sh'
-- :FloatermNew --autoclose=0 --wintype=split --height=0.4 bash %
-- elseif &filetype == 'python'
-- :FloatermNew --autoclose=0 --wintype=split --height=0.4 time python %
-- elseif &filetype == 'html'
-- silent! exec '!firefox % &'
-- elseif &filetype == 'markdown'
-- exec "MarkdownPreview"
-- elseif &filetype == 'lua'
-- set splitbelow
-- :sp
-- :term lua %
-- " elseif &filetype == 'tex'
-- " silent! exec "VimtexStop"
-- " silent! exec "VimtexCompile"
-- " elseif &filetype == 'dart'
-- " exec "CocCommand flutter.run -d ".g:flutter_default_device." ".g:flutter_run_args
-- " silent! exec "CocCommand flutter.dev.openDevLog"
-- " elseif &filetype == 'javascript'
-- " set splitbelow
-- " :sp
-- " :term export DEBUG="INFO,ERROR,WARNING"; node --trace-warnings .
-- " elseif &filetype == 'go'
-- " set splitbelow
-- " :sp
-- " :term go run .
-- endif
-- endfunc

-- ]])
